// subpkg/cinema/cinema.js
import { getCinimaInfo , getShowInfo} from '../../api/cinema'
const app = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    cinemaInfo: {},
    showInfo: {},
    currentShow: {},
    currentIndex: 0,
    selectDateIndex: 0
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getCinimaInfoData(options)
    this.getShowInfoData(options)
  },
  async getCinimaInfoData(options) {
    wx.showLoading({
      title: '拼命加载中...'
    })
    const res = await getCinimaInfo({cinemaId: options.cinemaId})
    this.setData({
      cinemaInfo: res.data
    })
  },
  async getShowInfoData(options) {
    const res = await getShowInfo(options)
    this.setData({
      showInfo: res.data,
      currentShow: res.data.movies[0]
    })
    wx.hideLoading()
  },
  bindchange(e) {
    this.setData({
      currentIndex: e.detail.current,
      currentShow: this.data.showInfo.movies[e.detail.current],
      selectDateIndex: 0
    })
  },
  selectDate(e) {
    this.setData({
      selectDateIndex: e.target.dataset.index
    })
  },
  // 去购票
  buyTicket(e) {
    app.globalData.movieBuyInfo = {...e.target.dataset.item,...this.data.currentShow,cinemaName:this.data.showInfo.cinemaName}
    wx.navigateTo({
      url: '/subpkg/seat/seat',
    })
  }
})